package com.example.entreamigoslocal;



import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;


public class NovoEventoActivity extends Activity {
	BdCadastro dbHelper = null;
	SQLiteDatabase db = null;

	ArrayAdapter<String> eventosAdapter = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_novo_evento);
		
		dbHelper = new BdCadastro(getApplicationContext());
		
		
	}

	public void convidar(View view){
		try{
    		EditText editNomeEvento = (EditText) findViewById(R.id.EditText_NomeEvento);
    		String nomeEvento = editNomeEvento.getText().toString();
    		
    		EditText editTipoEvento = (EditText) findViewById(R.id.editText1_Estilo);
    		String tipoEvento = editTipoEvento.getText().toString();
    		
    		EditText editDataEvento = (EditText) findViewById(R.id.editTextData);
    		String dataEvento = editDataEvento.getText().toString();
    		
    		db = dbHelper.getWritableDatabase();
    		
    		ContentValues values = new ContentValues();
    		values.put("NM_EVENTO", nomeEvento);
    		values.put("TP_EVENTO", tipoEvento);
    		values.put("DT_EVENTO", dataEvento);
    		
    		long resultado = db.insert("EVENTO", null, values);
    		
    		if(resultado != -1){
    			Toast.makeText(getApplicationContext(), "Evento criado com sucesso!", Toast.LENGTH_LONG).show();
    		}else{
    			Toast.makeText(getApplicationContext(), "Falha ao cadastrar evento", Toast.LENGTH_LONG).show();
    		}
    		db.close();
    		dbHelper.close();
    		    		
    		Intent i = new Intent(this,ContactsActivitys.class);
    		startActivity(i);
    		finish();
    		
    	}catch(Exception ex){
        	new AlertDialog.Builder(this).setMessage(ex.getMessage()).setPositiveButton("erro na excessao", null).show();
    	}
				
	}
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.novo_evento, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
